<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改商品')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: select2-css" />
</head>
<style>
    .divImg {
        float: left;
        margin: 2px;
        padding: 2px;
        height: 108px;
        width: 100px;
        border: 1px solid #dcdcdc;
        cursor: pointer;
    }
</style>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-goods-edit" th:object="${goodsGoods}">
        <input type="hidden" name="id" id="id" th:value="${goodsGoods.id}">
        <ul class="nav nav-tabs">
            <li class="active"><a href="#base" data-toggle="tab">基本信息</a>
            </li>
            <!--<li id="kzsx_tab" class="" style="display: none"><a href="#kzsx" data-toggle="tab">扩展属性</a>-->
            <!--</li>-->
            <li id="xxcs_tab" class="" style="display: block"><a href="#xxcs" data-toggle="tab">详细参数</a>
            </li>
            <!--<li class=""><a href="#inf" data-toggle="tab">商品介绍</a>-->
            <!--</li>-->
        </ul>
        <div class="tab-content text-center">
            <div class="tab-pane fade active in" id="base">
                <div class="row mb10">
                    <div class="col-lg-12">

                        <div class="form-group">
                            <label class="col-sm-3 control-label">商品名称：</label>
                            <div class="col-sm-8">
                                <input name="name" th:value="*{name}" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商品副标题：</label>
                            <div class="col-sm-8">
                                <textarea name="title" th:text="*{title}" class="form-control"></textarea>
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-3 control-label is-required">排序：</label>
                            <div class="col-sm-8">
                                <input class="form-control" th:value="*{sort}" type="text" name="sort" required>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">商品类别：</label>
                            <div class="col-sm-8">
                                <!--<input name="jumpIdArticle" class="form-control" type="text">-->
                                <select id="typeId" name="typeId" class="form-control m-b">
                                    <option th:each="dict : ${goodsTypeList}" th:text="${dict.name}"
                                            th:value="${dict.id}" th:field="*{typeId}"></option>
                                </select>
                            </div>
                        </div>
                        <input id="treeId" name="classId" type="hidden" th:field="*{classId}"/>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">分类：</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <input id="treeName" class="form-control" type="text"
                                           onclick="selectGoodsClassTree()"
                                           th:value="*{className}">
                                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">标签：</label>
                            <div class="col-sm-8">
                                <select id="tag" name="tag" class="form-control m-b" th:with="tag=${@dict.getType('goods_tag')}">
                                    <option th:each="dict : ${tag}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"  th:field="*{tag}"></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商品品牌：</label>
                            <div class="col-sm-8">
                                <select id="brandId" name="brandId" class="form-control m-b">
                                    <option>无</option>
                                    <option th:each="dict : ${brand}" th:text="${dict.name}"
                                            th:value="${dict.id}" th:field="*{brandId}"></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">主图：</label>
                            <div class="col-sm-8">
                                <button type="button" class="layui-btn" id="upload_main">上传图片</button>
                                <div class="layui-upload-list">
                                    <input type="hidden" id="mainUrl" th:value="*{mainUrl}" name="mainUrl">
                                    <input type="hidden" id="mainUrlReal" th:value="*{mainUrlReal}" name="mainUrlReal">
                                    <p id="show_main">
                                        <img th:src="*{mainUrl}" style="width:80px;height:80px;">
                                    </p>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><span style="color: red">*</span>商品轮播图</label>
                            <div class="col-sm-8">
                                <div style="text-align: left;">
                                    <button type="button" class="layui-btn" id="upload_img">上传图片</button>
                                </div>
                                <div class="layui-upload-list">
                                    <div id="img-url" style="padding: 5px;"></div>
                                    <!--<input type="hidden" id="logo" name="logo">-->
                                    <!--<p id="show_img"></p>-->
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><span style="color: red">*</span>商品详情</label>
                            <div class="col-sm-8">
                                <div style="text-align: left;">
                                    <button type="button" class="layui-btn" id="upload_detailsImg">上传图片</button>
                                </div>
                                <div class="layui-upload-list">
                                    <div id="detailsImg-url" style="padding: 5px;"></div>
                                    <!--<input type="hidden" id="logo" name="logo">-->
                                    <!--<p id="show_img"></p>-->
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label is-required">默认邮费：</label>
                            <div class="col-sm-8">
                                <input name="postFee" class="form-control" th:value="*{postFee}" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">启用规格：</label>
                            <div class="col-sm-8">
                                <select id="hasSpec" name="hasSpec" class="form-control m-b"
                                        th:with="spec=${@dict.getType('goods_has_spec')}">
                                    <option th:each="dict : ${spec}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}" th:field="*{hasSpec}"></option>
                                </select>
                            </div>
                        </div>
                        <!--<div id="sp_new" style="display: none">-->
                        </div>
                        <div class="form-group" id="sp_new" th:style="'display:'+ @{(*{hasSpec}!=0? 'none':'block')}">
                            <label class="col-sm-3 control-label">规格</label>
                            <div class="col-sm-8">
                                <button id="specBtn" class="btn btn-primary" style="float: left;" type="button">编辑规格
                                </button>
                                <div style="float: left;text-align: left;">
                                已设置<span th:text="${productNum}"></span>个规格货品 [
                                <span th:each="pList : ${goodsProducts}" th:text="${pList.spec}"></span>
                                ]</div>
                            </div>
                        </div>
                        <div class="form-group" id="showpriceO" th:style="'display:'+ @{(*{hasSpec}!=0? 'block':'none')}">
                            <label class="col-sm-3 control-label is-required">原价：</label>
                            <div class="col-sm-8">
                                <input name="priceO" class="form-control" type="text" th:value="${goodsProducts[0].priceO}">
                            </div>
                        </div>
                        <div class="form-group" id="showpriceN" th:style="'display:'+ @{(*{hasSpec}!=0? 'block':'none')}">
                            <label class="col-sm-3 control-label is-required">现价：</label>
                            <div class="col-sm-8">
                                <input name="priceN" class="form-control" type="text" th:value="${goodsProducts[0].priceN}">
                            </div>
                        </div>
                        <div class="form-group" id="showpriceVip" th:style="'display:'+ @{(*{hasSpec}!=0? 'block':'none')}">
                            <label class="col-sm-3 control-label is-required">会员价：</label>
                            <div class="col-sm-8">
                                <input name="priceVip" class="form-control" type="text" th:value="${goodsProducts[0].priceVip}">
                            </div>
                        </div>
                        <div class="form-group" id="showstock" th:style="'display:'+ @{(*{hasSpec}!=0? 'block':'none')}">
                            <label class="col-sm-3 control-label is-required">库存：</label>
                            <div class="col-sm-8">
                                <input name="stock" class="form-control" type="text" th:value="${goodsProducts[0].stock}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label is-required">销量：</label>
                            <div class="col-sm-8">
                                <input name="monthlySales" class="form-control" type="text" th:value="*{monthlySales}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">启用秒杀：</label>
                            <div class="col-sm-8">
                                <select id="hasSpike" name="hasSpike" class="form-control m-b"
                                        th:with="hasSpike=${@dict.getType('goods_has_spike')}">
                                    <option th:each="dict : ${hasSpike}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}" th:field="*{hasSpike}"></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="showspikeStart" th:style="'display:'+ @{(*{hasSpike}==0? 'none':'block')}">
                            <label class="col-sm-3 control-label">秒杀开始时间：</label>
                            <div class="col-sm-8">
                                <div class="input-group date">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input name="spikeStart" class="form-control"  placeholder="yyyy-MM-dd HH:mm:ss"
                                           type="text" th:value="${#dates.format(goodsGoods.spikeStart, 'yyyy-MM-dd HH:mm:ss')}">
                                </div>
                            </div>
                        </div>
                        <div class="form-group" id="showspikeEnd" th:style="'display:'+ @{(*{hasSpike}==0? 'none':'block')}">
                            <label class="col-sm-3 control-label">秒杀结束时间：</label>
                            <div class="col-sm-8">
                                <div class="input-group date">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input name="spikeEnd" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss"
                                           type="text" th:value="${#dates.format(goodsGoods.spikeEnd, 'yyyy-MM-dd HH:mm:ss')}">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否是品牌大牌：</label>
                            <div class="col-sm-8">
                                <div class="radio-box" th:each="dict : ${@dict.getType('goods_is_brand')}">
                                    <input type="radio" th:id="${'isBrand_' + dict.dictCode}" name="isBrand"
                                           th:value="${dict.dictValue}" th:checked="${dict.default}"
                                           th:field="*{isBrand}">
                                    <label th:for="${'isBrand_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否是境外产品：</label>
                            <div class="col-sm-8">
                                <div class="radio-box" th:each="dict : ${@dict.getType('goods_is_abroad')}">
                                    <input type="radio" th:id="${'isAbroad_' + dict.dictCode}" name="isAbroad"
                                           th:value="${dict.dictValue}" th:checked="${dict.default}"
                                           th:field="*{isAbroad}">
                                    <label th:for="${'isAbroad_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否是推荐产品：</label>
                            <div class="col-sm-8">
                                <div class="radio-box" th:each="dict : ${@dict.getType('goods_is_recommend')}">
                                    <input type="radio" th:id="${'isRecommend_' + dict.dictCode}" name="isRecommend"
                                           th:value="${dict.dictValue}" th:checked="${dict.default}"
                                           th:field="*{isRecommend}">
                                    <label th:for="${'isRecommend_' + dict.dictCode}"
                                           th:text="${dict.dictLabel}"></label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否是热卖产品：</label>
                            <div class="col-sm-8">
                                <div class="radio-box" th:each="dict : ${@dict.getType('goods_is_hot')}">
                                    <input type="radio" th:id="${'isHot_' + dict.dictCode}" name="isHot"
                                           th:value="${dict.dictValue}" th:checked="${dict.default}"
                                           th:field="*{isHot}">
                                    <label th:for="${'isHot_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                                </div>
                            </div>
                        </div>
                        <!--<div class="form-group">-->
                            <!--<label class="col-sm-3 control-label">能否积分折扣：</label>-->
                            <!--<div class="col-sm-8">-->
                                <!--<div class="radio-box" th:each="dict : ${@dict.getType('goods_is_point_discount')}">-->
                                    <!--<input type="radio" th:id="${'isPointDiscount_' + dict.dictCode}"-->
                                           <!--name="isPointDiscount" th:value="${dict.dictValue}"-->
                                           <!--th:checked="${dict.default}" th:field="*{recommend}">-->
                                    <!--<label th:for="${'isPointDiscount_' + dict.dictCode}"-->
                                           <!--th:text="${dict.dictLabel}"></label>-->
                                <!--</div>-->
                            <!--</div>-->
                        <!--</div>-->
                        <div class="form-group">
                            <label class="col-sm-3 control-label">状态：</label>
                            <div class="col-sm-8">
                                <div class="radio-box" th:each="dict : ${@dict.getType('goods_status')}">
                                    <input type="radio" th:id="${'status_' + dict.dictCode}" name="status"
                                           th:value="${dict.dictValue}" th:checked="${dict.default}"
                                           th:field="*{status}">
                                    <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                                </div>
                            </div>
                        </div>

                        <!--<div class="form-group">-->
                            <!--<label class="col-sm-3 control-label">分享标题：</label>-->
                            <!--<div class="col-sm-8">-->
                                <!--<input name="shareTitle" th:value="*{shareTitle}" class="form-control" type="text">-->
                            <!--</div>-->
                        <!--</div>-->


                        <!--<div class="form-group">-->
                            <!--<label class="col-sm-3 control-label">分享图：</label>-->
                            <!--<div class="col-sm-8">-->
                                <!--<button type="button" class="layui-btn" id="upload_share_img">上传图片</button>-->
                                <!--<div class="layui-upload-list">-->
                                    <!--<input type="hidden" id="shareImg" th:value="*{shareImg}" name="shareImg">-->
                                    <!--<p id="show_share">-->
                                        <!--<img th:src="*{shareImg}" style="width:80px;height:80px;">-->
                                    <!--</p>-->
                                <!--</div>-->
                            <!--</div>-->
                        <!--</div>-->
                    </div>
                </div>
            <div class="tab-pane fade" id="xxcs">
                <div class="form-group" th:each="params : ${typeParams}">
                    <div class="col-sm-12"  style="padding-bottom:5px;">
                        <div class="col-sm-10 input-group">
										<span class="input-group-btn">
										<button class="btn" style="width:120px;" type="button" th:text="${params.name}"></button>
										</span>
                            <input type="text" class="form-control" th:placeholder="${params.name}">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <input type="hidden" id="products" name="products">
        <input id="images" name="images" type="hidden">
        <input id="spec" name="spec" type="hidden">
        <input id="param" name="param" type="hidden">
        <input id="hhasSpec" name="hhasSpec" type="hidden" th:value="${goodsGoods.hasSpec==0?1:0}">
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: sortable-js"/>
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
    sessionStorage.setItem("products",JSON.stringify([[${goodsProducts}]]));
</script>
<script type="text/javascript"  th:inline="javascript">
    $(function(){
        //初始化商品参数
        var param=JSON.parse([[${goodsGoods.param}]]);
        $.each(param,function(j,k){
            $("#xxcs").find(".input-group").each(function(r,t){
                var self=$(this);
                if(self.find("button").html()== k.name){
                    self.find("input").val(k.value);
                }
            });
        });
    });


    var imgId=0;
    if([[${goodsBanner}]]!=undefined && [[${goodsBanner}]]!=[]) {
        var goodsBanner =[[${goodsBanner}]];
        var i = 0;
        for (o in goodsBanner) {
            i++;
            imgId++;
            $("#img-url").append("<div id='imgId" + imgId + "' class='divImg'>" +
                "<img  onclick=\"setImg('imgId" + imgId + "')\" src='" + goodsBanner[o].url + "' style='width:100px;height: 80px;margin-bottom: 1px;'><br>" +
                "<input type='hidden' name='imgBannerUrl' value='" + goodsBanner[o].url + "'>" +
                "<input type='hidden' name='imgBannerRealPath' value='" + goodsBanner[o].urlRealPath + "'>" +
                "<i style='float: right;padding-top: 4px;' class='fa fa-close' onclick=\"delImg('imgId" + imgId + "')\"></i></div>");
            // $("#logo").val(res.url);
        }
    }


    var container = document.getElementById("img-url");
    var sort = Sortable.create(container);


    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#upload_img'
            , url: '/common/upload' //改成您自己的上传接口
            , multiple: true
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    // $('#img-url').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')

                    var name= file.name.split(".")[0];
                    console.log(name)
                    $("#img-url").append("<div id='div" + name + "'><div  class='divImg'>" +
                        "<img  id='src" + name + "' src='' style='width:100px;height: 80px;margin-bottom: 1px;'><br>" +

                        "<i style='float: right;padding-top: 4px;' class='fa fa-close' onclick=\"delImg('div" + name + "')\"></i></div></div>");
                    // $("#logo").val(res.url);
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                imgId++;
                $("#div"+res.name).replaceWith("<div id='imgId" + imgId + "' class='divImg'>" +
                    "<img  onclick=\"setImg('imgId" + imgId + "')\" src='" + res.url + "' style='width:100px;height: 80px;margin-bottom: 1px;'><br>" +
                    "<input type='hidden' name='imgBannerUrl' value='" + res.url + "'>" +
                    "<input type='hidden' name='imgBannerRealPath' value='" + res.realPath + "'>" +
                    "<i style='float: right;padding-top: 4px;' class='fa fa-close' onclick=\"delImg('imgId" + imgId + "')\"></i></div>");

                sort.destroy();
                sort = Sortable.create(container);

            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText1');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    })



    var dimgId=0;
    if([[${goodsDetails}]]!=undefined && [[${goodsDetails}]]!=[]) {
        var goodsDetails =[[${goodsDetails}]];
        var i = 0;
        for (o in goodsDetails) {
            i++;
            dimgId++;
            $("#detailsImg-url").append("<div id='imgDetId" + dimgId + "' class='divImg'>" +
                "<img  onclick=\"setImg('imgId" + dimgId + "')\" src='" + goodsDetails[o].url + "' style='width:100px;height: 80px;margin-bottom: 1px;'><br>" +
                "<input type='hidden' name='imgDetailsUrl' value='" + goodsDetails[o].url + "'>" +
                "<input type='hidden' name='imgDetailsRealPath' value='" + goodsDetails[o].urlRealPath + "'>" +
                "<i style='float: right;padding-top: 4px;' class='fa fa-close' onclick=\"deldetImg('imgDetId" + dimgId + "')\"></i></div>");
            // $("#logo").val(res.url);
        }
    }


    var containerD = document.getElementById("detailsImg-url");
    var sortD = Sortable.create(containerD);


    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#upload_detailsImg'
            , url: '/common/upload' //改成您自己的上传接口
            , multiple: true
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    // $('#img-url').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')

                    var name= file.name.split(".")[0];
                    console.log(name)
                    $("#detailsImg-url").append("<div id='div" + name + "'><div  class='divImg'>" +
                        "<img  id='src" + name + "' src='' style='width:100px;height: 80px;margin-bottom: 1px;'><br>" +

                        "<i style='float: right;padding-top: 4px;' class='fa fa-close' onclick=\"delImg('div" + name + "')\"></i></div></div>");
                    // $("#logo").val(res.url);
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                dimgId++;
                $("#div"+res.name).replaceWith("<div id='imgDetId" + dimgId + "' class='divImg'>" +
                    "<img  onclick=\"setImg('imgId" + dimgId + "')\" src='" + res.url + "' style='width:100px;height: 80px;margin-bottom: 1px;'><br>" +
                    "<input type='hidden' name='imgDetailsUrl' value='" + res.url + "'>" +
                    "<input type='hidden' name='imgDetailsRealPath' value='" + res.realPath + "'>" +
                    "<i style='float: right;padding-top: 4px;' class='fa fa-close' onclick=\"delImg('imgDetId" + dimgId + "')\"></i></div>");

                sort.destroy();
                sort = Sortable.create(container);

            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText1');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });


        //普通图片上传
        upload.render({
            elem: '#upload_share_img'
            , url: '/common/upload' //改成您自己的上传接口
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                $("#show_share").html("<img src='" + res.url + "' style='width:80px;height:80px;'>");
                $("#shareImg").val(res.url);
            }
        });


    })



    var prefix = ctx + "system/goods";
    $("#form-goods-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {

            if ($("#hasSpec").val() == "1") {
                var specs = [];
                var spec = "";
                var priceO = $("input[name='priceO']").val();
                var priceN = $("input[name='priceN']").val();
                var priceVip = $("input[name='priceVip']").val();
                var stock = $("input[name='stock']").val();
                var icon = $("input[name='mainUrl']").val();
                var iconReal = $("input[name='mainUrlReal']").val();
                var name = $("input[name='name']").val();
                var isDefault = true;
                specs.push({
                    'spec': spec,
                    'name': name,
                    'priceO': priceO,
                    'priceN': priceN,
                    'priceVip': priceVip,
                    'icon': icon,
                    'iconReal': iconReal,
                    'isDefault': isDefault,
                    'stock': stock
                });
                $("#products").val(JSON.stringify(specs));
            }
            var params=[];
            $("#xxcs").find(".form-group").each(function(){
                var o={};
                o.name=$(this).find(".btn").text();
                o.value=$(this).find("input").val();
                params.push(o);
                // params.push(obj);
            });
            $("#param").val(JSON.stringify(params));
            $.operate.save(prefix + "/edit", $('#form-goods-edit').serialize());
        }
    }
    $("input[name='spikeStart']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true
    });


    $("input[name='spikeEnd']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true
    });


    /*菜单管理-新增-选择菜单树*/
    function selectGoodsClassTree() {
        var treeId = $("#treeId").val();
        var menuId = treeId != 1 ? treeId : 1;
        var url = "/system/goodsclass/selectGoodsClassTree/system-goods/" + menuId + "/a";
        var options = {
            title: '菜单选择',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }

    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#upload_main'
            , url: '/common/upload' //改成您自己的上传接口
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                $("#show_main").html("<img src='" + res.url + "' style='width:80px;height:80px;'>");
                $("#mainUrl").val(res.url);
                $("#mainUrlReal").val(res.realPath);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText1');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    })


    $("#hasSpike").on("change", function () {
        //不开启
        if ($(this).val() == 0) {
            //隐藏秒杀开始时间
            $("#showspikeStart").hide();
            //隐藏秒杀结束时间
            $("#showspikeEnd").hide();
        } else {//启用
            //展示秒杀开始时间
            $("#showspikeStart").show();
            //展示秒杀结束时间
            $("#showspikeEnd").show();
        }
    });


    $("#hasSpec").on("change", function () {
        //启用
        if ($(this).val() == 0) {
            //隐藏原价
            $("#showpriceO").hide();
            //隐藏现价
            $("#showpriceN").hide();
            //隐藏会员价
            $("#showpriceVip").hide();
            //显示库存
            $("#showstock").hide();
            //显示规格
            $("#sp_new").show();
        } else {//不启用
            //展示原价
            $("#showpriceO").show();
            //展示现价
            $("#showpriceN").show();
            //展示会员价
            $("#showpriceVip").show();
            //显示库存
            $("#showstock").show();
            //显示规格
            $("#sp_new").hide();
        }
    });



    $("#specBtn").on("click", function () {
        // $("#specHtml").load("/beaut/goodsGoods/spec?id="+$("#typeId").val()+"&sku="+$("#sku").val()+"&price="+$("#price").val()+"&priceMarket="+$("#priceMarket").val()+"&weight="+$("#weight").val(), function (response, status, xhr) {
        //     console.log("加载外页面111111");
        //     // $("#dialogSpec").modal("show");
        //     console.log("加载外页面结束======================");
        // });
        layer.open({
            type: 2,
            title: "选择规格",
            area: ['800px'],
            maxmin: true,
            content: prefix + "/spec?id=" + $("#typeId").val()+"&type="+$("#hhasSpec").val()
        })
    });

    function specEditBtn66() {
        layer.full(layer.open({
            type: 2,
            title: "编辑规格",
            // area : [ '800px' ],
            maxmin: true,
            content: prefix + "/spec?id=" + $("#typeId").val() + "&type="+$("#hhasSpec").val()
        }));
    }

    $("#typeId").on("change", function () {
        getType($(this).val());
    });


    function getType(id) {
        getParam(id);
    }

    function getParam(id){
        $.post("/system/goods/getParam" , {"id":id}, function (paramdata) {
            if(paramdata.code==0){
                var str='';
                $.each(paramdata.data,function(i,param){
                    str+='<div class="form-group">';
                    // str+='<label class="col-sm-3 control-label">'+param.name+'</label>';

                    str += '<div class="col-sm-12" style="padding-bottom:5px;">' +
                        '<div class="col-sm-10 input-group">' +
                        '<span class="input-group-btn">' +
                        '<button class="btn" style="width:120px;" type="button">'+ param.name+'</button>';
                    str += '</span><input type="text" class="form-control" placeholder="'+ param.name+'"></div></div>';

                    str+='</div>';

                });
                $("#xxcs").html(str);
            }else {
                $("#xxcs").html('');
            }
        }, "json");
    }


    function delImg(id) {
        $("#" + id).remove();
    }

    function setImg(id) {
        $("#img").find("div").each(function () {
            $(this).removeClass("divImgD").addClass("divImg");
        });
        $("#" + id).removeClass("divImg");
        $("#" + id).addClass("divImgD");
    }

    function deldetImg(id) {
        $("#" + id).remove();
    }

</script>
</body>
</html>